package communication;

import java.io.IOException;
import java.net.ServerSocket;
import javax.net.ssl.SSLServerSocketFactory;

public class ServerSecureConnectionManagerControlled{

	
	private ServerSocket socket;
	private int bandwidth;
		

	public ServerSecureConnectionManagerControlled(int port,int bandwidth)
	throws ConnectionException{	
		try {
			socket = SSLServerSocketFactory.getDefault().createServerSocket(port);
			this.bandwidth = bandwidth;
		} catch (IOException e){
			throw new ConnectionException(e.getMessage());
		}
	}


	public Connection acceptConnection()
	throws ConnectionException{
		try {
			return new ServerSecureConnectionControlled(socket.accept(),bandwidth);
		} catch (IOException e) {
			throw new ConnectionException(e.getMessage());
		}
	}


	public void close()
	throws ConnectionException{
		try {
			if(socket!=null){
				socket.close();
				socket = null;
			}
		} catch (IOException e) {
			throw new ConnectionException(e.getMessage());
		}
	}


}
